/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: DuKe TeAm
 * License Type: Purchased
 */
package orm.impl;

import org.orm.*;
import org.hibernate.Query;
import java.util.List;
import orm.*;

public class CoordenadaDAOImpl implements orm.dao.CoordenadaDAO {
	public Coordenada loadCoordenadaByORMID(int idcoordenada) throws PersistentException {
		try {
			PersistentSession session = orm.PinpassPersistentManager.instance().getSession();
			return loadCoordenadaByORMID(session, idcoordenada);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Coordenada getCoordenadaByORMID(int idcoordenada) throws PersistentException {
		try {
			PersistentSession session = orm.PinpassPersistentManager.instance().getSession();
			return getCoordenadaByORMID(session, idcoordenada);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Coordenada loadCoordenadaByORMID(int idcoordenada, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.PinpassPersistentManager.instance().getSession();
			return loadCoordenadaByORMID(session, idcoordenada, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Coordenada getCoordenadaByORMID(int idcoordenada, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.PinpassPersistentManager.instance().getSession();
			return getCoordenadaByORMID(session, idcoordenada, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Coordenada loadCoordenadaByORMID(PersistentSession session, int idcoordenada) throws PersistentException {
		try {
			return (Coordenada) session.load(orm.Coordenada.class, new Integer(idcoordenada));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Coordenada getCoordenadaByORMID(PersistentSession session, int idcoordenada) throws PersistentException {
		try {
			return (Coordenada) session.get(orm.Coordenada.class, new Integer(idcoordenada));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Coordenada loadCoordenadaByORMID(PersistentSession session, int idcoordenada, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Coordenada) session.load(orm.Coordenada.class, new Integer(idcoordenada), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Coordenada getCoordenadaByORMID(PersistentSession session, int idcoordenada, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Coordenada) session.get(orm.Coordenada.class, new Integer(idcoordenada), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Coordenada[] listCoordenadaByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.PinpassPersistentManager.instance().getSession();
			return listCoordenadaByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Coordenada[] listCoordenadaByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.PinpassPersistentManager.instance().getSession();
			return listCoordenadaByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Coordenada[] listCoordenadaByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Coordenada as Coordenada");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			List list = query.list();
			return (Coordenada[]) list.toArray(new Coordenada[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Coordenada[] listCoordenadaByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Coordenada as Coordenada");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			List list = query.list();
			return (Coordenada[]) list.toArray(new Coordenada[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Coordenada loadCoordenadaByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.PinpassPersistentManager.instance().getSession();
			return loadCoordenadaByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Coordenada loadCoordenadaByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.PinpassPersistentManager.instance().getSession();
			return loadCoordenadaByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Coordenada loadCoordenadaByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		Coordenada[] coordenadas = listCoordenadaByQuery(session, condition, orderBy);
		if (coordenadas != null && coordenadas.length > 0)
			return coordenadas[0];
		else
			return null;
	}
	
	public Coordenada loadCoordenadaByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		Coordenada[] coordenadas = listCoordenadaByQuery(session, condition, orderBy, lockMode);
		if (coordenadas != null && coordenadas.length > 0)
			return coordenadas[0];
		else
			return null;
	}
	
	public static java.util.Iterator iterateCoordenadaByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.PinpassPersistentManager.instance().getSession();
			return iterateCoordenadaByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateCoordenadaByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.PinpassPersistentManager.instance().getSession();
			return iterateCoordenadaByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateCoordenadaByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Coordenada as Coordenada");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateCoordenadaByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Coordenada as Coordenada");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Coordenada createCoordenada() {
		return new orm.Coordenada();
	}
	
	public boolean save(orm.Coordenada coordenada) throws PersistentException {
		try {
			orm.PinpassPersistentManager.instance().saveObject(coordenada);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean delete(orm.Coordenada coordenada) throws PersistentException {
		try {
			orm.PinpassPersistentManager.instance().deleteObject(coordenada);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.Coordenada coordenada)throws PersistentException {
		try {
			if(coordenada.getTarjeta_idtarjeta() != null) {
				coordenada.getTarjeta_idtarjeta().coordenada.remove(coordenada);
			}
			
			return delete(coordenada);
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.Coordenada coordenada, org.orm.PersistentSession session)throws PersistentException {
		try {
			if(coordenada.getTarjeta_idtarjeta() != null) {
				coordenada.getTarjeta_idtarjeta().coordenada.remove(coordenada);
			}
			
			try {
				session.delete(coordenada);
				return true;
			} catch (Exception e) {
				return false;
			}
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean refresh(orm.Coordenada coordenada) throws PersistentException {
		try {
			orm.PinpassPersistentManager.instance().getSession().refresh(coordenada);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean evict(orm.Coordenada coordenada) throws PersistentException {
		try {
			orm.PinpassPersistentManager.instance().getSession().evict(coordenada);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Coordenada loadCoordenadaByCriteria(CoordenadaCriteria coordenadaCriteria) {
		Coordenada[] coordenadas = listCoordenadaByCriteria(coordenadaCriteria);
		if(coordenadas == null || coordenadas.length == 0) {
			return null;
		}
		return coordenadas[0];
	}
	
	public Coordenada[] listCoordenadaByCriteria(CoordenadaCriteria coordenadaCriteria) {
		return coordenadaCriteria.listCoordenada();
	}
}
